﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public partial class TQOSTEP : ViewBase
    {
        #region ==QCORDER===========
        public static readonly DependencyProperty QCORDERProperty = DependencyProperty.Register("QCORDER",
            typeof(string), typeof(TQOSTEP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnQCORDERChanged));
        public string QCORDER
        {
            get
            {
                return (string)GetValue(QCORDERProperty);
            }
            set
            {
                SetValue(QCORDERProperty, value);
                ((VQOSTEP)MV).QCORDER = value;
                LOADQS();
            }
        }
        private static void OnQCORDERChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TQOSTEP;
            if (src != null)
            {
                src.QCORDER = (string)e.NewValue;
            }
        }
        #endregion

        #region ==QPLAN===========
        public static readonly DependencyProperty QPLANProperty = DependencyProperty.Register("QPLAN",
            typeof(string), typeof(TQOSTEP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnQPLANChanged));
        public string QPLAN
        {
            get
            {
                return (string)GetValue(QPLANProperty);
            }
            set
            {
                SetValue(QPLANProperty, value);
                ((VQOSTEP)MV).QPLAN = value;
            }
        }
        private static void OnQPLANChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TQOSTEP;
            if (src != null)
            {
                src.QPLAN = (string)e.NewValue;
            }
        }
        #endregion

        #region ==YCOUNT===========
        public static readonly DependencyProperty YCOUNTProperty = DependencyProperty.Register("YCOUNT",
            typeof(string), typeof(TQOSTEP),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnYCOUNTChanged));
        public string YCOUNT
        {
            get
            {
                return (string)GetValue(YCOUNTProperty);
            }
            set
            {
                SetValue(YCOUNTProperty, value);
                ((VQOSTEP)MV).YCOUNT = value;
            }
        }
        private static void OnYCOUNTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TQOSTEP;
            if (src != null)
            {
                src.YCOUNT = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwQC===========
        public static readonly DependencyProperty dwQCProperty = DependencyProperty.Register("dwQC",
            typeof(DataRow), typeof(TQOSTEP),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwQCChanged));
        public DataRow dwQC
        {
            get
            {
                return (DataRow)GetValue(dwQCProperty);
            }
            set
            {
                SetValue(dwQCProperty, value);
            }
        }
        private static void OdwQCChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TQOSTEP;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwQC = row;
            }
        }
        #endregion

        public TQOSTEP()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VQOSTEP();
            MESSAGES += "REFRESHBYGB33;";
            this.DataContext = MV;
            InitializeComponent();
            IsEdit = false;
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwQC = dwMaster;
        }

        public override void OnWorkflowIDChange(ReflectionStudio.Core.Events.MessageEventArgs e)
        {
            base.OnWorkflowIDChange(e);
            MessageInfo msg = e.Info;
            string task = msg.MSGTYPE;
            switch (task)
            {
                case "REFRESHBYGB33":
                    ((VQOSTEP)MV).REFRESHBYGB33(msg);
                    break;
            }
        } 
       
        public void LOADQS()
        {
            if (QCORDER.Length < 9)
            {
                TBMain.Clear();
                return;
            }
            dwData = TBMain.NewRow();
            dwData["QOEMANDANT"] = app.Mandant;
            dwData["QOEORDER"] = QCORDER;
            SResult = ((VQOSTEP)MV).QueryQOSTEP(dwData, 1);
            MergeData(SResult, false); 
        } 

        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
            base.SaveCommand(sender, e);
        }

    }
}
